﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;

namespace WebApp.Controls
{
    public partial class GoodsChoice : System.Web.UI.UserControl
    {
        private ProductManager m_ProductManager = new ProductManager();
        


        private int m_ShowCount = 10;
        public int ShowCount
        {
            get { return m_ShowCount; }
            set { m_ShowCount = value; }
        }


        private string m_imageSrc = "../imagesWeb/Rec01.gif";
        public string ImageSrc
        {
            get { return m_imageSrc; }
            set { m_imageSrc = value; }
        }

        private bool m_IsRecommend;

        public bool IsRecommend
        {
            get { return m_IsRecommend; }
            set
            {
                m_IsRecommend = value;
                this.BindProduct();
            }
        }



        protected void Page_Load(object sender, EventArgs e)
        {
            this.BindProduct();
        }

        private void BindProduct()
        {
            try
            {
                this.lvProduct.DataSource = this.m_ProductManager.GetGoodChoiceProducts().Cast<object>().Take(m_ShowCount);
                this.lvProduct.DataBind();
            }
            catch
            {

            }
        }

        protected void lvProduct_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            int i;
            HtmlImage img = e.Item.FindControl("img") as HtmlImage;

            if (img != null)
            {
                i = Convert.ToInt16(e.Item.ClientID.Substring(e.Item.ClientID.Length - 7, 1)) * 5 + Convert.ToInt16(e.Item.ClientID.Substring(e.Item.ClientID.Length - 2)) + 1;
                if (i < 10)
                {
                    img.Src = "../imagesWeb/Rec0" + i.ToString() + ".gif";
                }
                else
                {
                    img.Src = "../imagesWeb/Rec" + i.ToString() + ".gif";
                }
            }

            Label lb = e.Item.FindControl("Label1") as Label;
            if (lb.Text.Length > 10)
            {
                lb.Text = lb.Text.Substring(0, 10);
            }
        }
    }
}